/**
 * 
 */
package tech.client.services;

import java.util.List;


import org.mymmsc.android.app.util.AndroidXmlParser;
import org.mymmsc.android.app.util.XmlResult;
import org.mymmsc.api.http.HttpClient;

import tech.client.base.Global;


/**
 * @author etong
 *
 */
public abstract class ProxyDriver {
	protected final static String SRV_HTTP_EXT = "EChannel-Control:etong/X-Mobile-Client_1.0.1";
	//private static String SRV_HOST = "http://www.etong.mobi";
    protected static String SRV_HOST = "http://192.168.1.203";
	protected static String xPayHost = "http://www.etong.so:7002";
	
	/**
	 * 请求一个列表
	 * 
	 * @param <T>
	 * @param <V>
	 * @param domain
	 * @param xml
	 * @param clazz
	 * @return
	 */
	protected static <T, V> List<V> getList(String domain, String xml, Class<V> clazz) {
		AndroidXmlParser xp = null;
		List<V> list = null;
		String msg = "";
		msg = HttpClient.PostXml(domain, xml, SRV_HTTP_EXT, "utf-8", Global.EXP_TIMEOUT);
		if (msg != null) {
			xp = new AndroidXmlParser(msg);
			try {
				list = xp.valueOf5("item", clazz);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
	/**
	 * 执行一个远程操作请求，等待服务器响应一个XmlResult的结果
	 * 
	 * @param domain
	 * @param xml
	 * @see XmlResult
	 * @return
	 */
	protected static XmlResult get(String domain, String xml) {
		XmlResult xRet = null;
		AndroidXmlParser xp = null;
		String msg = "";
		msg = HttpClient.PostXml(domain, xml, SRV_HTTP_EXT, "utf-8", Global.EXP_TIMEOUT);
		if (msg != null) {
			xp = new AndroidXmlParser(msg);
			try {
				xRet = xp.valueOf("response", XmlResult.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if (xRet == null) {
			xRet = new XmlResult();
		}
		return xRet;
	}
}
